import { get,post } from '@/utils/request'
const state = () => ({
  // 用来保存查询出来的栏目信息
  categorys: [],
  total: 0,
});

const actions = {
  // 注意actions中第一个参数是context
  // 查询所有栏目信息
  findAllCategory(context, list) {
    // 异步操作
    get("/productCategory/pageQuery", list).then((res) => {
      let response = res.data.list;
      let total = res.data.total
      context.commit('SET_CATEGORYS', response)
      context.commit('SET_TOTAL', total)
    });
  },
  // 保存栏目的信息
  saveCategory(context,list) {
    // response 是一个承诺对象
    let response = post('/productCategory/saveOrUpdate',list)
    return response
  },
  
  // 删除某行栏目
  deleteCategory(context,list){
    let response = get('/productCategory/deleteById',list)
    return response
  }
};

const mutations = {
  // 修改state中的值
  SET_CATEGORYS(state, response) {
    state.categorys = response
  },
  SET_TOTAL(state, total) {
    state.total = total
  }
};



export default {
  namespaced: true,
  state,
  mutations,
  actions,
};